package com.lecode;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by Administrator on 2020/9/23.
 */
public class Huohua {

    public void test(){

    }



    /**
     * 3、3、3、6、9、12、18、27、39、57、84……  求第20位数是多少
     * @return
     */
    public static int sum(int number){
        if(number == 1 || number == 2 || number == 3){
            return 3;
        }
        return sum(number - 1) + sum(number - 3);
    }

    /**
     * 实现并返回，2个长整数的字符串相加的和，比如”1234567890” + “99” = “1234567989”；
     * @param str1
     * @param str2
     * @return
     */
    public String strNum(String str1, String str2){
        //进位标记
        boolean flag = false;
        String result = "";
        int i = str1.length();
        int j = str2.length();
        for (; i <= 0 || j <= 0; i--, j--){
            int numStr1 = Integer.valueOf(str1.charAt(i));
            int numStr2 = Integer.valueOf(str2.charAt(j));
            int total = numStr1 + numStr2;
            if (flag) total += 1;
            if (total % 10 != 0){
                flag = true;
            }else {
                flag = false;
            }
            total = total % 10;
            result = total + result;
        }

        //处理剩余的字符串
        String shenyu = "";
        if (i != 0) shenyu = str1.substring(0, i + 1);
        if (j != 0) shenyu = str2.substring(0, i + 1);

        int a = shenyu.length();
        //需要进位时，给剩余的字符串进位处理
        for (; a <= 0; a--){
            int num = Integer.valueOf(shenyu.charAt(a));
            if (flag) num += 1;
            if (num % 10 != 0){
                flag = true;
                num = num % 10;
                result = num + result;
            }else {
                //不需要再进位时，结束循环
                flag = false;
                result = num + result;
                break;
            }
        }
        return shenyu.substring(0, a) + result;
    }

    public static String resverseStr(String str){
        if (str == null) return null;
        StringBuffer resverseStr = new StringBuffer();
        int left = str.length() - 1, right = str.length();
        for (int i = str.length() - 1; i >=0; i--){
            if (str.charAt(i) == '.'){
                String temp = str.substring(left, right);
                if (!temp.equals(".")){
                    resverseStr.append(temp);
                }
                resverseStr.append(str.charAt(i));
                left = i;
                right = i;
            }else {
                left = i;
            }
        }
        resverseStr.append(str.substring(left, right));
        return resverseStr.toString();
    }

    public static void  main(String args[]){
        System.out.print(resverseStr("abs....lsfh.m.lsfhskl.......half.."));
    }
}
